﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace SQL_Manager
{
    public delegate void NewDelegate();
    //
    // This whole form is just to mess around with
    //                    x)
    //
    public partial class frmPlayerLookup : Form
    {
        OTServ.Player player;
        public frmPlayerLookup()
        {
            InitializeComponent();
        }

        public delegate void hallRunPls();

        private void cmdGo_Click(object sender, EventArgs e)
        {
            Threader.ThreadFire((tEventFire)delegate { this.threadOnWait(); }, (tEventFire)delegate { this.threadedLoadPlayer(this.txtName.Text); }, (tEventFire)delegate { this.threadOnResume(); });
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.player != null)
            {
                if (this.player.commit() < 1)
                {
                    MessageBox.Show("Didn't save :'(");
                }
            }
        }

        #region Threaded Events
        //
        // Threaded Events
        //
        private void threadedLoadPlayer(string name)
        {
            try
            {
                this.Invoke((tEventFire)delegate { this.player = new OTServ.Player(name); this.playerBindingSource.DataSource = this.player; });
            }
            catch (Exceptions.PlayerNotFoundException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private delegate void pbLoaderControl();

        private void threadOnWait()
        {
            this.pbLoader.Invoke((tEventFire)delegate { this.pbLoader.Visible = true; });
        }

        private void threadOnResume()
        {
            this.pbLoader.Invoke((tEventFire)delegate { this.pbLoader.Visible = false; });
        }
        #endregion
    }
}
